<template>
    <el-layout>
        <el-form ref="form" :model="project" label-width="80px">
            <el-form-item label="项目名称">
                <el-input v-model="project.name"></el-input>
            </el-form-item>
            <el-form-item label="项目描述">
                <el-input v-model="project.desc"></el-input>
            </el-form-item>
            <el-form-item label="活动时间">
                <el-col :span="11">
                    <el-date-picker type="date" placeholder="选择日期" v-model="project.start_time" style="width: 100%;"></el-date-picker>
                </el-col>
                <el-col class="line" :span="2">-</el-col>
                <el-col :span="11">
                    <el-time-picker placeholder="选择时间" v-model="project.end_time" style="width: 100%;"></el-time-picker>
                </el-col>
            </el-form-item>
            <el-form-item label="团队">
                <el-input v-model="project.team"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="update">保存</el-button>
            </el-form-item>
        </el-form>
    </el-layout>
</template>
<script>
    export default {
        name: "ProjectBase",
        props: {
            projectId: {
                type: String,
                required: true,
                default: ""
            }
        },
        data() {
            return {
                project: {
                    id: "",
                    name: "",
                    desc: "",
                    team: "",
                    start_time: "",
                    end_time: "",
                    status: 0
                }
            }
        },
        created () {
            this.loadProjectData(this.projectId);
        },
        methods: {
            loadProjectData: function (projectId) {
                let self = this;
                let url = '/api/project/get';
                this.$http.post(url, {
                    id: projectId
                }).then(res => {
                    self.project = res.data.project;
                }).catch(err => {
                    console.log(err);
                });
            },
            update() {
                let self = this;
                let url = '/api/project/update';
                this.$http.post(url, self.project).then(res => {
                    this.$message({
                        message: "操作成功"
                    })
                }).catch(err => {
                    console.log(err);
                });
            }
        }
    }
</script>
<style lang="scss" scoped>
</style>